<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <title>e网生活管理后台</title>
  <?php include("common/conn.php"); if($_SESSION['userid']==""){echo "<script>window.location.href='login.php';</script>";} 

  if($_GET['action']=="ok"){    
    $query = mysql_query("INSERT INTO buyer_service (type,name) VALUES (".$_POST[type].",'".$_POST[name]."')");
    if (mysql_affected_rows()>0) {
      echo "<script>alert('添加成功');window.location.href='buyer.php?type=".$_POST[type]."';</script>";
    }else{
      echo "<script>alert('添加成功');window.location.href='buyer.php?type=".$_POST[type]."';</script>";
    }
    
  }




  if($_GET['ch']=="ok"){ 
    $query = mysql_query("UPDATE buyer_service set type=".$_POST[type].",name='".$_POST[name]."' where id=".$_POST[id]);
    if (mysql_affected_rows()>0) {
      echo "<script>alert('更新成功');window.location.href='buyer.php?type=".$_POST[type]."';</script>";
    }else{
      echo "<script>alert('更新失败');window.location.href='buyer.php?type=".$_POST[type]."';</script>";
    }
    
  }

  if($_GET['id']!=""){
    $query = mysql_query("select * from buyer_service where id=".$_GET[id]);
    $service = mysql_fetch_assoc($query);
  }
  ?>
  <script type="text/javascript" src="js/jquery.min.js"></script>
  <link href="css/styles.css" rel="stylesheet" type="text/css" />
</head>

<body>

  <!--header-->
  <?php include("common/header.php");?>
  <!--header end-->


  <!-- staqrt subnav -->
  <div id="sub_nav">

    <div id="subnav_wrap" class="container_12">

      <!-- start sub nav list -->
      <div id="subnav" class=" grid_12">

        <ul>
          <li> <a href="fenlei.php"> 分类管理 </a></li>
          <li><a href="buyer.php" class="sub_nav_active" >分类属性</a></li>
        </ul>

      </div>

    </div>


  </div>
  <div class="container_12">
    <form action="?<?php if($_GET['id']!=""){echo "ch=ok";}else{echo "action=ok";} ?>" method="post">
      <input type="hidden"  name="id"  value="<?php echo $service[id];?>">
      <h2>添加买家服务</h2>  	
      <label>所属分类</label>
      <select name="type">
        <option value="0" <?php if ($service[type] == 0) { ?> selected="selected" <?php } ?>>海淘</option>
        <option value="1" <?php if ($service[type] == 1) { ?> selected="selected" <?php } ?>>快购</option>
      </select>
      <br/><br/>
      <label>服务名称</label>
      <input name="name"  type="text" value="<?php echo $service[name];?>">
      <br/><br/>



      <input  type="submit" value="提交" /></div>
    </form>       
  </div>
</form>
</body>
</html>
